﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Labs.Entity
{
    public sealed class Employee : TaxEntity, IPayable
    {
        const decimal TAXRATE = .0765m;

        private decimal salary;
        private decimal ytdSalary;
        private decimal ytdTaxes;

        public Employee(string name, string ssn)
            : this(name, ssn, 100)
        {}

        public Employee(string name, string ssn, float sal)
            : base(name, ssn)
        {
            Salary = (decimal)sal;
        }

        public override string TaxIdRegex
        {
            get { return @"^\d\d\d-\d\d-\d\d\d\d$"; }
        }

  
        public decimal Salary
        {
            get { return salary; }
            set { 
                if (value > 10 && value < 1000)
                    salary = value;
                else
                    throw new ArgumentOutOfRangeException();
            }
        }

        public decimal YtdSalary
        {
            get { return ytdSalary; }
        }
        public decimal YtdTaxes
        {
            get { return ytdTaxes; }
        }

        /// <summary>
        /// Pays this employee it's current salary, incrementing
        /// 
        /// </summary>
        /// <returns>Net pay (gross - taxes)</returns>
        public sealed override decimal Pay()
        {
            decimal taxes = Salary * TAXRATE;
            ytdTaxes += taxes;
            ytdSalary += Salary;
            return Salary - taxes;
        }

        public static void Main()
        {
           
            Console.WriteLine("Taxrate is {0}", TAXRATE);

            Employee e = new Employee("Chuck", "123", 100);

            e = null;

            // what is e.Name? e.Salary?
            
            Console.WriteLine(e.Name);  // getter
            e.Salary = 100m;
            Console.WriteLine("Just paid {0}", e.Pay());

        }

    }


    

}
